//
//  NSObject+Print.swift
//  04-表情键盘
//
//  Created by Admin on 16/9/18.
//  Copyright © 2016年 itcast. All rights reserved.
//

import Foundation

extension NSObject {
    
    class func printIvars() {
        // 记录属性总数
        var count: UInt32 = 0
        
        // 获取UIPageControl里面的所有属性
        let ivars = class_copyIvarList(self, &count)
        
        // 遍历
        for i in 0..<count {
            // 获取属性数组里面的属性
            let ivar = ivars![Int(i)]
            
            // 获取属性的名称
            let cName = ivar_getName(ivar)
            //  UnsafePointer<Int8>?
            
            // 转成String
            let name = String(cString: UnsafePointer<CChar>(cName!), encoding: String.Encoding.utf8)
            
            print("name: \(name)")
        }
        
        free(ivars)
    }
}
